package actions;

import objects.SpetialFeature;
import factory.Constants;
import universe.Universe;
import interfaces.impl.Action;

public class ActionGetHouse extends Action{
	
	public ActionGetHouse(){
		super();
		this.id=Constants.ACTION_GET_HOUSE;
		
	}

	public ActionGetHouse(int priority){
		super(priority);
		this.id=Constants.ACTION_GET_HOUSE;
		
	}

	@Override
	public boolean processAction(Universe world) {
		SpetialFeature nPersons=null;
		SpetialFeature totalPersons=null;
		for(SpetialFeature fe : target.getListFeatures()){
			if(fe.getId()==Constants.SPETIAL_FEATURE_NUMBER_PERSON){
				nPersons=fe;
			}
			if(fe.getId()==Constants.SPETIAL_FEATURE_TOTAL_NUMBER_PERSON){
				totalPersons=fe;
			}
		}
		if(totalPersons!=null && nPersons!=null){
			if(nPersons.getValue()<totalPersons.getValue()){
				
				SpetialFeature house=null;
				for(SpetialFeature f : source.getListFeatures()){
					if(f.getId()==Constants.SPETIAL_FEATURE_HOUSE){
						if(f.getValue()!=Constants.TRUE){
							nPersons.setValue(nPersons.getValue()+1);
							f.setValue(Constants.TRUE);
							return true;							
						}
					}
				}
				
			}
		}
		
		return false;
	}

	@Override
	public String getName() {
		// TODO Auto-generated method stub
		return null;
	}
	

}
